<template>
	<u-tabbar v-show="showTabbar" v-model="current" :activeColor="tabbarStyle.st_color" :inactiveColor="tabbarStyle.ust_color"
		:list="tabbarList" height="104" @changeCenterLogo="changeCenterLogoFunc"></u-tabbar>
</template>
<script>
	import Cache from '@/utils/cache'
	import {
		DISTRIBUTION,
		NAVIGATIONMENU,
	} from '@/config/cachekey'
	
	import { mapGetters } from 'vuex'
	export default {
		data() {
			return {
				currentRoute: '',
				currentCenterLogo:'/static/images/center_0.png',
			}
		},
		methods: {
			changeCenterLogoFunc(e){
				this.currentCenterLogo = e;
			}
		},
		props: {
			isShowBar: {
				type: Boolean,
				defaults: false
			}
		},
		mounted() {
			const currentPages = getCurrentPages()
			const currentPage = currentPages[currentPages.length - 1]
			this.currentRoute = currentPage.route
		},
		computed: {
			...mapGetters(['appConfig','navigationMenu']),
			tabbarStyle() {
				return this.appConfig.navigation_setting || {}
			},
			tabbarList() {
				const localTabBar = [
					{
						is_distribution_show: 0,
						name: "首页",
						page_path: "pages/index/index",
						un_selected_icon: "/static/images/index1.png",
						selected_icon: "/static/images/index2.png",
						status: 1,
					},
					{
						is_distribution_show: 0,
						name: "分类",
						page_path: "pages/cate_list/cate_list",
						un_selected_icon: "/static/images/cat1.png",
						status: 1,
						selected_icon: "/static/images/cat2.png",
					},
					{
						is_distribution_show: 0,
						name: " ",
						page_path: "pages/index/index2",
						un_selected_icon: "/static/images/index1.png",
						status: 1,
						selected_icon: "/static/images/index2.png"
					},
					{
						is_distribution_show: 0,
						name: "服务",
						page_path: "pages/member/member",
						un_selected_icon: "/static/images/member1.png",
						status: 1,
						selected_icon: "/static/images/member2.png"
					},
					{
						is_distribution_show: 0,
						name: "我的",
						page_path: "pages/user/user",
						un_selected_icon: "/static/images/my1.png",
						status: 1,
						selected_icon: "/static/images/my2.png"
					}
				];
				const tabbar = this.navigationMenu.length ? this.navigationMenu : localTabBar;
				console.log('==tabbar.vue==computed==tabbarList==tabbar=================', this.navigationMenu.length);
				console.log(this.navigationMenu);
				return tabbar.filter((item) => item.status == 1).map((item) => {
					return {
						// iconPath: item.un_selected_icon,
						// selectedIconPath: item.selected_icon,
						iconPath: item.page_path == 'pages/index/index2' ? this.currentCenterLogo : item.un_selected_icon,
						selectedIconPath: item.page_path == 'pages/index/index2' ? this.currentCenterLogo : item.selected_icon,
						text: item.name,
						midButton: item.page_path == 'pages/index/index2' ? true : false,
						withText: item.page_path == 'pages/index/index2' ? false : true,
						count: item.page_path == 'bundle/pages/shop_cart/shop_cart' ? this.cartNum : 0,
						pagePath: '/' + item.page_path
					}
				})
			},
			showTabbar() {
				if(this.isShowBar){
					return true;
				}
				const current = this.tabbarList.findIndex((item) => {
					return item.pagePath === '/' + this.currentRoute
				})
				return current >= 0
			},
			...mapGetters(['cartNum']),
		}
	}
</script>
